package com.shiro.test01;


import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;

/**
 * Created by Administrator on 2018/7/21/021.
 */
public class TestHelloWord {


    public static void test() {
        IniSecurityManagerFactory factory = new IniSecurityManagerFactory(
                "classpath:shiro-first.ini");

        SecurityManager instance = factory.getInstance();

        SecurityUtils.setSecurityManager(instance);
        Subject subject = SecurityUtils.getSubject();//请求

        UsernamePasswordToken token = new UsernamePasswordToken("zhangsan", "111111");
        subject.login(token);
        System.out.println("是否通过认证:" + subject.isAuthenticated());
        subject.logout();
        System.out.println("是否通过认证:" + subject.isAuthenticated());
    }

    public static void main(String[] args) {
        test();
    }

}
